package org.csu.jpetstore.web.servlet;

import org.csu.jpetstore.domain.Account;
import org.csu.jpetstore.domain.Order;
import org.csu.jpetstore.service.LogService;
import org.csu.jpetstore.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ViewMyOrderServlet extends HttpServlet {

    private static final String VIEW_MY_ORDER = "/WEB-INF/jsp/order/ViewMyOrder.jsp";
    Account loginAccount;
    private LogService logService;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        logService = new LogService();
        HttpSession session = request.getSession();
        loginAccount = (Account)session.getAttribute("loginAccount");

        OrderService orderService = new OrderService();
        List<Order> orderList = orderService.getOrderByUser(loginAccount.getUsername());
        session.setAttribute("orderList",orderList);

        request.getRequestDispatcher(VIEW_MY_ORDER).forward(request, response);

    }
}
